package com.example.demo.controller;

import com.example.demo.common.domain.Hotel;
import com.example.demo.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;


@Controller
public class SearchController {
    @Autowired
    private SearchService searchService;

    @RequestMapping("/SearchHotel")
    public String SearchHotel(String Destination , String KeyWord, String CheckIntime , String CheckOuttime, Model model,HttpSession session){
        System.out.println(Destination+";"+KeyWord);
        session.setAttribute("CheckIntime",CheckIntime);
        session.setAttribute("CheckOuttime",CheckOuttime);
        List<Hotel> hotelList=searchService.SearchHotel(Destination,KeyWord);
        model.addAttribute("hotels",hotelList);
        model.addAttribute(Destination,Destination);
        model.addAttribute(KeyWord,KeyWord);

    return "search";}

    @RequestMapping("/map")
    public String map(String Destination , String KeyWord,Model model) {
        System.out.println(Destination+";"+KeyWord);
        List<Hotel> hotelList=searchService.SearchHotel(Destination,KeyWord);
        model.addAttribute("hotelList",hotelList);
        return "views/baidu";
    }

}
